﻿using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;

namespace TomAndJerryMidnightSnack
{

    class LoseScreen : GameScreen
    {

        Texture2D backgroundTexture;
        Texture2D PlayAgainTexture;
        Texture2D FinalScoreTexture;

        Vector2 instructionPosition;
        Vector2 playPosition;

        SpriteFont font;
        /// <summary>
        /// Constructor.
        /// </summary>
        public LoseScreen()
            : base()
        {
            //sound effect for game
            //AudioManager.PushMusic("LoseTheme",false);
            this.Exiting += new EventHandler(LoseScreen_Exiting);
        }


        void LoseScreen_Exiting(object sender, EventArgs e)
        {
            //stop music
            //AudioManager.PopMusic();
        }

        public override void LoadContent()
        {
            ContentManager content = ScreenManager.Game.Content;
            Viewport viewport = ScreenManager.GraphicsDevice.Viewport;

            backgroundTexture = content.Load<Texture2D>(@"losepage");
            PlayAgainTexture = content.Load<Texture2D>(@"Buttons\again");
            FinalScoreTexture = content.Load<Texture2D>(@"Text\finalScore");

            font = content.Load<SpriteFont>(@"Fonts\gameFont");

            instructionPosition = new Vector2(100, 36);
            playPosition = new Vector2(100, 450);
        }

        /// <summary>
        /// UnloadContent
        /// </summary>

        public override void UnloadContent()
        {
            base.UnloadContent();
        }

        /// <summary>
        /// Handles user input.
        /// </summary>
        public override void HandleInput()
        {
            if (InputManager.IsButtonClicked(new Rectangle(
                (int)playPosition.X - PlayAgainTexture.Height, (int)playPosition.Y,
                (int)(PlayAgainTexture.Height),
                (int)(PlayAgainTexture.Width))))
            {
                GameScreen screen = new HomeScreen();
                ExitScreen();
                ScreenManager.AddScreen(screen);
                //Debug.WriteLine("Touch");
            }
            base.HandleInput();
        }

        /// <summary>
        /// Updates the menu.
        /// </summary>
        public override void Update(GameTime gameTime, bool otherScreenHasFocus,
                                                       bool coveredByOtherScreen)
        {

            base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen);
        }


        /// <summary>
        /// Draws the menu.
        /// </summary>
        public override void Draw(GameTime gameTime)
        {
            SpriteBatch spriteBatch = ScreenManager.SpriteBatch;
            ScreenManager.GraphicsDevice.SetRenderTarget(ScreenManager.FinalImageTarget);
            ScreenManager.GraphicsDevice.Clear(Color.CornflowerBlue);

            // we will do all of our drawing here
            ScreenManager.GraphicsDevice.SetRenderTarget(null);

            spriteBatch.Begin();
            spriteBatch.Draw(backgroundTexture, new Vector2(480, 0), null, Color.White, MathHelper.PiOver2, Vector2.Zero, Vector2.One, SpriteEffects.None, 0f);
            spriteBatch.Draw(FinalScoreTexture, new Vector2(400,100), null, Color.White, MathHelper.PiOver2, Vector2.Zero, Vector2.One, SpriteEffects.None, 0f);
            spriteBatch.DrawString(font, ""+ ScreenManager.Score, new Vector2(300, 300), Color. CadetBlue, MathHelper.PiOver2, Vector2.Zero, 2f, SpriteEffects.None, 0f);
            spriteBatch.Draw(PlayAgainTexture, playPosition, null, Color.White, MathHelper.PiOver2, Vector2.Zero, Vector2.One, SpriteEffects.None, 0f);
            spriteBatch.End();
        }

    }
}

